 
 capture cd "D:\Dropbox\book_welfare\replication"
 
 
 
 **********************************
 *Note: the code takes a long time.  
 

 use data\book_author_mapping.dta,clear 
		keep book_id pubyr mshare genre1 
		duplicates drop 
		tempfile b 
		save `b'
 
 import delimited user_id_map.csv, clear 
		tempfile u 
		save `u'
	
	
use data\part10m0.dta, clear 
	forvalues k=1(1) 22{
		append using data\part10m`k'.dta 
	}


	merge m:1 user_id using `u'
	drop user_id review_id
	rename user_id_csv user_id 

	drop _merge 


	merge m:1 user_id using   data\user_genre.dta



	foreach x in dromance dchildren dcomics dfantasy dfiction dhistory dmystery dnonfiction dpoetry dyoungadult { 	
		su `x', de 
		local m=r(p50)
			
		gen q`x' = `x' >	`m'
	}
	
	gen year=year(ddate)
	collapse (sum)  qdromance qdchildren qdcomics qdfantasy qdfiction qdhistory qdmystery qdnonfiction qdpoetry qdyoungadult, by(year book_id)  	

	
***********************
***********************
	

	keep book_id  year  qdromance qdchildren qdcomics  qdfantasy  qdfiction qdhistory qdmystery qdnonfiction qdpoetry qdyoungadult



	merge 1:1 book_id year using clean\books_year.dta
	drop _merge 

	
save data\books_year_types.dta, replace 
